export default {
  data () {
    return {
      selectedNode: '',
      selectedAreaNode: '',
      selectedChannelNode:'',
      curPagePath: ''
    }
  },
  created() {
    let userLoginId = window.sessionStorage.getItem('loginid')
    this.curPagePath = userLoginId+'-'+this.$route.path
    let curPageCache = window.localStorage.getItem(this.curPagePath)
    let _curPageCache = curPageCache ? JSON.parse(curPageCache) : {}
    this.selectedNode = _curPageCache.parkNames ? _curPageCache.parkNames : ''
    this.selectedAreaNode = _curPageCache.areaNames ? _curPageCache.areaNames : ''
    this.selectedChannelNode = _curPageCache.channelNames ? _curPageCache.channelNames : ''
  },
  methods: {
    setSelectedNode (params) {
      this.selectedNode = params.name || '';
      this.$emit('setSelectedNode',params)
    },
    setSelectedAreaNode (params) {
      this.selectedAreaNode = params.areaNames || '';
      this.$emit('setSelectedAreaNode', params)
    },
    setSelectedChannelNode (channelArr) {
      let channelNames = []
      for(let i = 0; i<channelArr.length; i++){
        let obj = channelArr[i]
        channelNames.push(obj.channelName)
      }
      this.selectedChannelNode = channelNames.join(',') || ''
      this.$emit('setSelectedChannelNode',channelArr)
    },
  }
}
